//
//  HMSearchView.swift
//  Weibo
//
//  Created by 吴少飞 on 16/9/19.
//  Copyright © 2016年 wushaofei. All rights reserved.
//

import UIKit

class HMSearchView: UIView {

    @IBOutlet weak var searchBtn: UIButton!
    @IBOutlet weak var searchTextField: UITextField!

    @IBOutlet weak var searchFieldConstraint: NSLayoutConstraint!
    

    //监听文本框
    @IBAction func textFieldEditing(_ sender: AnyObject) {
        
        searchFieldConstraint.constant = searchBtn.width+4
        UIView.animate(withDuration: 0.3) {
            
            self.layoutIfNeeded()
        }
        
    }
    
    //搜索按钮点击事件
    @IBAction func search(_ sender: AnyObject) {
        
        searchTextField.resignFirstResponder()
        
        searchFieldConstraint.constant = 0;
        
        UIView.animate(withDuration: 0.3) { 
            
            self.layoutIfNeeded()
        }
    }
    
    //创建xib的类方法
    class func searchView()->HMSearchView{
        
        return UINib(nibName: "HMSearchView", bundle: nil).instantiate(withOwner: nil, options: nil).last! as! HMSearchView
    }
}
